<template>
  <div class="shopCarContainer-container">
    <!-- 购物车商品列表区 -->
    <!-- <div class="shopcar-list" v-for="(item,i) in carlist" :key="item.id">
      <div class="mui-card">
        <div class="mui-card-content">
          <div class="mui-card-content-inner">
            
            <mt-switch 
               v-model="this.$store.getters.getGoodsSelected[item.id]"
               @change = "selectedChanged(item.id,this.$store.getters.getGoodsSelected[item.id])"
               ></mt-switch>
            <img src="../../images/phone1.jpg" alt />
            <div class="info">
              <h3>小米mi 3200像素 双摄</h3>
              <p>
                <span class="price">￥{{item.price}}</span>
                <numbox></numbox>
                <a href="#" @click.prevent='remove(item.id,i)'>删除</a>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>-->
    <div class="shopcar-list">
      <div class="mui-card">
        <div class="mui-card-content">
          <div class="mui-card-content-inner">
            <mt-switch></mt-switch>
            <img src="../../images/phone1.jpg" alt />
            <div class="info">
              <h3>小米mi 3200像素 双摄</h3>
              <p>
                <span class="price">￥2199</span>
                <numbox></numbox>
                <a href="#">删除</a>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 结算区域 -->
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总计(不含运费)</p>
            <p>已勾选商品<span class="red">{{this.$store.getters.getGoodsCountAndAmount.count}}</span> 件，总价<span class="red">￥{{this.$store.getters.getGoodsCountAndAmount.amount}}</span></p>
          </div>
          <mt-button type="danger">去结算</mt-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import numbox from "../subcomponents/Shopcar_numbox.vue";
export default {
  data() {
    return {
      id: this.$route.params.id,
      carlist: [
        //拿到的购物车的数据对象
        //  {cou:1,id:07,title:'华为荣耀6Plus 16G双版',sell_price:2195,thumb_path:'/src/images/phone1.jpg'}
      ]
    };
  },
  created() {
    this.getCarlist();
  },
  methods: {
    getCarlist() {
      // 拿到store中car存储的对象，拿到里面的id值，使用字符串进行拼接
      var idArr = [];
      this.$store.state.car.forEach(item => {
        idArr.push(item.id);
      });
      if (idArr.length <= 0) {
        return;
      }
      this.$http
        .get("api/goods/getshopcarlist/" + idArr.join(","))
        .then(result => {
          if (result.body.status === 0) {
            this.carlist = result.body.message;
          }
        });
    },
    //删除当前购物车的商品
    remove(id, index) {
      this.carlist.splice(i, 1);
      this.$store.commit("removeCar", id);
    },
    selectedChanged(id,val){
      this.$store.commit('updateSelected',{id,selected:val});
    }

  },
  components: {
    numbox
  }
};
</script>
<style lang="scss" scoped>
.shopCarContainer-container {
  background: #eee;
  overflow: hidden;

  .shopcar-list {
    .mui-card-content-inner {
      display: flex;
      align-items: center;
    }
    .mint-switch {
      display: flex;
      position: relative;
      align-items: center;
    }
    img {
      width: 50px;
      height: 50px;
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      h3 {
        font-size: 13px;
        margin-bottom: 10px;
      }
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
  .jiesuan {
    display: flex;
    justify-content: space-between;
    align-items:center;
    .red{
      color:red;
      font-weight:bold;
      font-size:16px;
    }
  }
}
</style>
